package com.sosee.cgfw.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.sosee.cgfw.R;
import com.lidroid.xutils.BitmapUtils;

import java.util.List;

/**
 * Created by Thinkpad on 2016/2/15.
 */
public class BrandAdapter extends BaseAdapter {
    BitmapUtils bitmapUtils;
    private List<String> list;

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    private LayoutInflater inflater;
    public BrandAdapter(Context context){
        inflater=LayoutInflater.from(context);
        bitmapUtils=new BitmapUtils(context);
    }
    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolderBrand holder=null;
        if(view==null){
            view=inflater.inflate(R.layout.item_brand,null);
            holder=new ViewHolderBrand();
            holder.ig= (ImageView) view.findViewById(R.id.ig);
            view.setTag(view);
        }else{
            holder= (ViewHolderBrand) view.getTag();
        }
        String url=list.get(i);
        bitmapUtils.display(holder.ig,url);
        return view;
    }

    class ViewHolderBrand{
        ImageView ig;
    }
}
